package com.yn.module.spider.utils.base;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yn.module.spider.web.dto.SpiderMonitorDTO;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public abstract class BaseService<M extends BaseMapper<T>,T> extends ServiceImpl<M ,T>  {
    /**
     * 查询爬取数据的进展
     *
     * @param totalPages 总页数
     * @return
     */
    public Map<String, Object> queryData4Monitor(SpiderMonitorDTO dto) {
        dto.setCurrentDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        List<Map<String, Object>> dataList = baseMapper.queryData4Monitor(dto);
        if (ObjectUtils.isEmpty(dataList)) return new HashMap<>();
        return dataList.get(0);
    }
}
